package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JDBCDemo11 {
    public static void main(String[] args) {
        try (Connection connection = DBUtil.getConnection();){
            String sql = "INSERT INTO userinfo (username,password,nickname,age) VALUES ('泰罗奥特曼','909090','泰罗',200)";
            connection.setAutoCommit(false);
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            int num = preparedStatement.executeUpdate();
            System.out.println(num>0?"插入成功":"插入失败");
//            connection.rollback();
//            System.out.println("事务回滚了");
            connection.commit();
            System.out.println("事务提交成功");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
